# -*-coding:utf-8 -*-

"""
# File       : getBiliData.py
# Time       ：2022/7/30 下午12:50
# Author     ：puppet
# version    ：python 3.8.1
# Description：
"""
import requests
import time
import emoji


def getBiliVideoHotList():
    url = "https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all"
    res = requests.get(url=url)
    videosList = []
    for video in res.json()['data']['list']:
        videoTempList = []
        author = emoji.demojize(video['owner']['name'])
        avatorLink = video['owner']['face']
        title = str(emoji.demojize(video['title']))
        videoLink = video['short_link_v2']
        videoPic = video['pic']
        videoTimeLong = round(int(video['duration']) / 60, 2)
        classfy = video['tname']

        pubDate = str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(video['pubdate'])))
        pubLocation =video['pub_location'] if video.get('pub_location') else 'no_pub_location'
        hitRank = video['stat']['his_rank']
        view = video['stat']['view']
        favorite = video['stat']['favorite']
        videoTempList = [author, avatorLink, title, videoLink, videoPic, videoTimeLong, classfy, pubDate, pubLocation,
                         hitRank, view, favorite]
        videosList.append(videoTempList)
    return videosList


# a = getBiliVideoHotList()
# for i in a:
#     if "真是绝妙好" in str(i[2]):
#         print(i[2])